import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

class GoodsBaseInfo extends StatelessWidget {
  final Map baseInfo;
  const GoodsBaseInfo({ Key key, this.baseInfo }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        _imageSwipper(),
        _goodsTitle(),
        _goodsNumber(),
        _goodsPrice()
      ],
    );
  }

  Widget _imageWidget (String url) {
    return Container(
      width: ScreenUtil().setWidth(750),
      height: ScreenUtil().setHeight(750),
      decoration: BoxDecoration(
        image: DecorationImage(image: NetworkImage(url), fit: BoxFit.fitWidth)
      ),
    );
  }

  // 商品主图
  Widget _imageSwipper () {
    return Container(
      width: ScreenUtil().setWidth(750),
      height: ScreenUtil().setHeight(750),
      child: Swiper(
        autoplay: true,
        pagination: SwiperPagination(),
        itemCount: baseInfo['mainPics'].length,
        itemBuilder: (context, index) {
          return Image.network(baseInfo['mainPics'][index], fit: BoxFit.fill);
        },
      )
    );
  }

  // 商品标题
  Widget _goodsTitle () {
    return Padding(
      padding: EdgeInsets.all(8.0),
      child: Text(
        baseInfo['goodsName'],
        style: TextStyle(
          fontSize: 16.0,
          fontWeight: FontWeight.w700
        ),
        maxLines: 2,
        overflow: TextOverflow.ellipsis,
      ),
    );
  }

  // 商品编号
  Widget _goodsNumber () {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 8.0),
      child: Text('项目编号: ${baseInfo['id']}', style: TextStyle(fontSize: 12.0, color: Colors.grey[600]),),
    );
  }

  // 商品价格
  Widget _goodsPrice () {
    return Padding(
      padding: EdgeInsets.all(8.0),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          Text('￥${baseInfo['price']}', style: TextStyle(fontSize: 20.0, color: Colors.pink, fontWeight: FontWeight.w700),),
          SizedBox(width: 16.0),
          Text('市场价: ', style: TextStyle(fontSize: 14.0, color: Colors.black54, fontWeight: FontWeight.w700),),
          Text('￥${baseInfo['price']}', style: TextStyle(color: Colors.black54, decoration: TextDecoration.lineThrough),)
        ],
      ),
    );
  }
}